<?php
/**
 * 发一个GET请求获取数据
 */
function get($url)
{
   global $curl;
   // 生成一个curl对象
	$curl = curl_init();
   // 配置curl中的http协议->可配置的荐可以查PHP手册中的curl_
   curl_setopt($curl, CURLOPT_URL, $url);
   //curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
   //curl_setopt($curl, CURLOPT_HEADER, FALSE);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
   curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
   // 执行这个请求
   return curl_exec($curl);
}

function getHTTPS($url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_REFERER, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $result = curl_exec($ch);
  curl_close($ch);
  return $result;
}
  
//$data=file_get_contents("https://www.zhihu.com/question/38627388");
  
 

$url='https://www.zhihu.com/question/41392204';
$data=getHTTPS($url);
 $list_preg = "/<div class=\"RichContent-inner\".*?>.*?<\/div>/ism";
  $span2_preg = '/<span class="(.*)" itemprop="(.*)" data-reactid="(.*)"><\/a>/U';
  $span_preg = "/<span class=\"RichText CopyrightRichText-richText\".*?>.*?<\/span>/ism";
  $p_preg = "/<span class=\"RichText CopyrightRichText-richText\" itemprop=\"text\" data-reactid=\"(.*)\">.*?<\/span>/ism";
  $quchu = "/<span class=\"RichText CopyrightRichText-richText\" itemprop=\"text\" data-reactid=\"(.*)\">/U";
  $quchu1 = "/$<\/span>/ism"; 
preg_match_all($list_preg,$data,$list);
$i=1;
foreach ($list[0] as $k => $v) {
	preg_match($p_preg,$v,$span);
	$str = preg_replace($quchu, '', $span[0]);
	$str = str_replace('</span>','',$str);
	$str = str_replace('</p>','',$str);
	$str = str_replace('<p>','',$str);
	$str = str_replace('<br>','',$str);
	//preg_match($p_preg,$span[0],$p);
	$log = date('YmdHis');
	$open=fopen("./".$log.".txt","a" );
	fwrite($open,$str."\r\n");
	fclose($open);
	// preg_match($p_preg,$span[0],$p);
	var_dump($str);
	$i++;
}
exit;
?>